import sys

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import *
from PyQt6.QtGui import *

from src.compents.ImageView import ImageView
from src.compents.MdiArea import MdiArea
from src.compents.device_setting_pannel import DeviceSettingPanel

class MainWindow(QMainWindow):
    def __init__(self,parent = None):
        super().__init__(parent)
        self.resize(1280,720)
        self.setWindowTitle('Spec General Editor')
        self.mdi_area = MdiArea()
        self.init_menu_bar()
        self.init_sub_window()


    def init_menu_bar(self):
        '''
        设置顶端菜单栏
        :return: None
        '''
        bar = self.menuBar()  # 获取菜单栏对象
        file = bar.addMenu('File')
        window = bar.addMenu('Window')  # 在菜单栏中添加一个菜单叫做'窗口'
        test = bar.addMenu('Test')
        test.addAction('create img')  # 在'窗口'菜单中添加一个动作叫做'新建'

        test.triggered[QAction].connect(self.menu_bar_actionFunc)
    def menu_bar_actionFunc(self,fAction):
        if fAction.text() == 'create img':
            imgaeView = ImageView()
            self.mdi_area.create_sub_window(imgaeView)
            self.mdi_area.setWidget(self.mdi_area.mdi)


    def init_sub_window(self):
        #初始化基础窗口在界面上
        device_setting_panel = DeviceSettingPanel()
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, device_setting_panel)
        #self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea,self.mdi_area)
        #self.mdi_area.setAllowedAreas(Qt.DockWidgetArea.RightDockWidgetArea | Qt.DockWidgetArea.BottomDockWidgetArea)
        self.splitDockWidget(device_setting_panel, self.mdi_area, Qt.Orientation.Horizontal)

    def create_sub_window(self, dock_widget_inst):
        # 创建新的窗口
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea,dock_widget_inst)

